﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using MaxStudio.Concrete.DBUtility;
using MaxStudio.Concrete.Server.Dao;
using MaxStudio.Concrete.Server.Interface;

namespace MaxStudio.Concrete.Server.Service
{
    public class RPTCementReviewService : ServiceHandle, IRPTCementReview
    {
        #region IRPTCementReview Members

        public OperationResult<List<tb_RPT_CementReview>> GetAllCementReview()
        {
            OperationResult<List<tb_RPT_CementReview>> result = new OperationResult<List<tb_RPT_CementReview>>();
            List<tb_RPT_CementReview> list = new List<tb_RPT_CementReview>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                list = dataContext.GetAllCementReview();
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<List<tb_RPT_CementReview>> GetCementReviewByProjectName(string strProjectName)
        {
            OperationResult<List<tb_RPT_CementReview>> result = new OperationResult<List<tb_RPT_CementReview>>();
            List<tb_RPT_CementReview> list = new List<tb_RPT_CementReview>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                list = dataContext.GetCementReviewByProjectName(strProjectName);
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<List<tb_RPT_CementReview>> GetCementReviewByContition(string strProjectName, string strProdCode,
                                                            string strFactoryNumbers, string strIntoFactoryDate, string strTestDate)
        {
            OperationResult<List<tb_RPT_CementReview>> result = new OperationResult<List<tb_RPT_CementReview>>();
            List<tb_RPT_CementReview> list = new List<tb_RPT_CementReview>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                list = dataContext.GetCementReviewByContition(strProjectName,strProdCode,strFactoryNumbers,strIntoFactoryDate ,strTestDate );
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<tb_RPT_CementReview> GetCementReviewById(int id)
        {
            ConcreteDaoDataContext dataContext = getDateContext();
            OperationResult<tb_RPT_CementReview> result = new OperationResult<tb_RPT_CementReview>();
            tb_RPT_CementReview cementReview;
            try
            {
                cementReview = dataContext.GetCementReviewById(id);
                if (cementReview == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = cementReview;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<tb_RPT_CementReview> CreateCementReview(tb_RPT_CementReview entity)
        {
            OperationResult<tb_RPT_CementReview> result = new OperationResult<tb_RPT_CementReview>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                dataContext.CreateCementReview(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        public OperationResult<tb_RPT_CementReview> ModifyCementReview(tb_RPT_CementReview entity)
        {
            OperationResult<tb_RPT_CementReview> result = new OperationResult<tb_RPT_CementReview>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                dataContext.ModifyCementReview(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        public OperationResult<tb_RPT_CementReview> DeleteCementReview(tb_RPT_CementReview entity)
        {
            OperationResult<tb_RPT_CementReview> result = new OperationResult<tb_RPT_CementReview>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                dataContext.DeleteCementReview(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        #endregion
    }
}
